home *** CD-ROM | disk | FTP | other *** search
- /* bt_find.c - find function */
- #include "stdio.h"
- #include "btree.h"
- #include "bt_macro.h"
-
- extern IX_DESC *pci ;
-
- int find_ix(pe,pix) /* finds first entry with a key */
- ENTRY *pe ; /* points to key to be matched */
- /* store the rec. loc. here */
- IX_DESC *pix ; /* points to index descriptor */
- { /* returns success = 1, failure= 0 */
- int ret ;
- ENTRY tempe ;
-
- pci = pix ;
- /* be sure target is < dummy */
- if( call(pci->pcomp) (pe,&pci->dx.dume) >= 0 )
- { go_last(pix) ; /* no - position at end */
- return( 1 ) ; /* and return not equal */
- }
-
- ret = find_level(pci->dx.nl,pe,pci->dx.rb) ;
- if( ret == 0 ) /* if an entry was found */
- { copy_current(0,&tempe) ; /* store it's record pointer */
- pe->rptr = tempe.rptr ;
- }
- return( ret ) ;
- }
-
-
- int find_level(l,pe,r) /* find a key within a level */
- int l ; /* the level */
- ENTRY *pe ; /* the target entry */
- RECPOS r ; /* the block to look in */
- {
- BLOCK b ;
- int ret , off ;
-
- retrieve_block(l,r,&b,CURR) ; /* get current block */
- /* look for the key there */
- ret = find_block(pe,&b,&off,pci->pcomp) ;
- CB(1) = r ; /* make this the current block */
- CO(1) = off ; /* and offset in the block */
-
- if( l > 0 ) /* now search lower levels */
- ret = find_level(l-1,pe,ENT_ADR(&b,off)->rptr) ;
- return( ret ) ;
- }
-
-
-